package com.juneng.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.juneng.common.R;
import com.juneng.utils.CosApi;
import com.juneng.utils.Func;

import java.io.File;
import java.util.List;

import com.juneng.utils.Uploadutil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import com.juneng.entity.AudioFrequency;
import com.juneng.dto.AudioFrequencyDto;
import com.juneng.dto.AudioFrequencyQueryDto;
import com.juneng.vo.AudioFrequencyVo;
import com.juneng.service.IAudioFrequencyService;
import org.springframework.web.multipart.MultipartFile;

/**
 * 音频表 控制器
 *
 * @author zds
 * @since 2021-07-14
 */
@RestController
@AllArgsConstructor
@RequestMapping("audioFrequency/v1")
@Api(tags = "音频表相关接口")
public class AudioFrequencyController {

	private IAudioFrequencyService audioFrequencyService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperation(value = "详情", notes = "传入id")
	public R<AudioFrequency> detail(Integer id) {
		AudioFrequency detail = audioFrequencyService.getById(id);
		return R.success(detail);
	}

	/**
	 * 分页 音频表
	 */
	@GetMapping("/page")
	@ApiOperation(value = "分页", notes = "传入audioFrequency")
	public R<IPage<AudioFrequencyVo>> page(AudioFrequencyQueryDto dto) {
		IPage<AudioFrequencyVo> pages = audioFrequencyService.page(dto);
		return R.success(pages);
	}
	/**
	 * 列表 音频表
	 */
	@GetMapping("/list")
	@ApiOperation(value = "不分页", notes = "传入audioFrequency")
	public R<List<AudioFrequency>> list(AudioFrequencyQueryDto dto) {
		List<AudioFrequency> list = audioFrequencyService.list(dto);
		return R.success(list);
	}

	/**
	 * 新增 音频表
	 */
	@PostMapping("/save")
	@ApiOperation(value = "新增", notes = "传入audioFrequency")
	public R save(@RequestBody AudioFrequencyDto dto) {
		return R.success(audioFrequencyService.save(dto));
	}

	/**
	 * 修改 音频表
	 */
	@PutMapping("/update")
	@ApiOperation(value = "修改", notes = "传入audioFrequency")
	public R update(@RequestBody AudioFrequencyDto dto) {
		return R.success(audioFrequencyService.updateById(dto));
	}

	/**
	 * 删除 音频表
	 */
	@DeleteMapping("/remove")
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.success(audioFrequencyService.deleteLogic(Func.toIntList(ids)));
	}

	@PostMapping("/uploadVid")
	@ApiOperation(value = "音视上传接口", notes = "传入ids")
	@Transactional(rollbackFor = Exception.class)
	public R<?> uploadVid( MultipartFile path){
		try {
			File file = CosApi.multipartFileToFile(path);
			String  videoId = Uploadutil.uploadVideo2(file);
			return R.success(videoId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return R.failed();
	}
}
